package com.yoomiito.app.ui.list

import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.model.sdd.SddFreeGoodsOrderInfo
import com.yoomiito.app.utils.ImageLoader
import com.yoomiito.app.utils.ResUtil
import de.hdodenhof.circleimageview.CircleImageView

class ReceiverListAdapter(data: List<SddFreeGoodsOrderInfo>?) : BaseQuickAdapter<SddFreeGoodsOrderInfo, BaseViewHolder>(R.layout.item_receiver, data) {

    override fun convert(helper: BaseViewHolder?, item: SddFreeGoodsOrderInfo?) {
        helper?.getView<CircleImageView>(R.id.userPic).let {
            ImageLoader.getInstance().into(mContext, item?.headimgurl, it)
        }
        helper?.getView<TextView>(R.id.statusTv).let {
            when (item?.apply_state) {//0待确认，1同意，2拒绝，3已超时
                0 -> {
                    it?.setTextColor(ResUtil.getColor(R.color.color_FF035B))
                    it?.background = ResUtil.getDrawable(R.drawable.bg_border_ff035b)
                    it?.text = "确认"
                    it?.isEnabled = true
                    helper?.addOnClickListener(R.id.statusTv)
                }
                else -> {
                    it?.setTextColor(ResUtil.getColor(R.color.color_balk_999999))
                    it?.isEnabled = false
                    it?.text = when (item?.apply_state) {
                        1 -> "已领取"
                        2 -> "已拒绝"
                        else -> "已超时"
                    }
                    val lp = it?.layoutParams as LinearLayout.LayoutParams
                    lp.height = LinearLayout.LayoutParams.WRAP_CONTENT
                }
            }
        }
    }
}